package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Space;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.LoginActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.MyLikeClubActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Club;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Success;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.model.ClubModel;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by Lix on 2018/10/12.
 */

public class MyLikeClubAdapter extends RecyclerView.Adapter<MyLikeClubAdapter.ViewHolder> {
    private List<Club> mClub;
    private Context mContext;
    mOnItemClickListener mOnItemClickListener;

    public MyLikeClubAdapter(Context mContext, List<Club> mClub){
        this.mContext = mContext;
        this.mClub = mClub;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public MyLikeClubAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.like_club_cardview ,parent,false);
        MyLikeClubAdapter.ViewHolder holder = new MyLikeClubAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyLikeClubAdapter.ViewHolder holder, final int position) {
        final Club club = mClub.get(position);
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener!=null) {
                    mOnItemClickListener.onClick(v, position);
                }
            }
        };
        holder.club_name.setText(club.getClub_name());
        holder.club_address.setText(club.getAddress());
        holder.btn_unlike.setOnClickListener(onClickListener);
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+club.getPic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.club_img);
    }



    @Override
    public int getItemCount() {
        return mClub.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        ImageView club_img;
        TextView club_name;
        TextView club_address;
        Button btn_unlike;
        FrameLayout club_container;

        public ViewHolder(View view){
            super(view);
            club_img = (ImageView)view.findViewById(R.id.like_club_img);
            club_name = (TextView)view.findViewById(R.id.like_club_name);
            club_address = (TextView)view.findViewById(R.id.like_club_address);
            btn_unlike = (Button)view.findViewById(R.id.unlike_club_btn);
            club_container = (FrameLayout)view.findViewById(R.id.like_club_container);


        }


    }

    public interface mOnItemClickListener {
        void onClick(View view, int position);
    }

    public void setmOnItemClickListener(MyLikeClubAdapter.mOnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
}
